import { Component, OnInit } from '@angular/core';
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/operator/switchMap';
import { Router, ActivatedRoute, Params } from '@angular/router';

import { Task, TaskService } from './service/task.service';

@Component({
  selector: 'user-list',
  templateUrl: './user-list.component.html',
  styleUrls: [
    './user-list.component.css'
  ]
})

export class UserListComponent implements OnInit {
  tasks: Observable<Task[]>;

  constructor(
    private taskService: TaskService,
    private route: ActivatedRoute
  ){}

  ngOnInit(){
    this.tasks = this.route.params
      .switchMap((params: Params) => {
        return this.taskService.getTasks();
      });
  }
}
